package com.ccsoft.nio;

import java.io.*;
import java.nio.channels.FileChannel;

// 通过 channel 的 transferFrom 拷贝文件
public class Ch05ChannelCopy {
    public static void main(String[] args) throws IOException {
        File srcFile = new File("d:\\filechannel.txt");
        FileInputStream srcStream = new FileInputStream(srcFile);
        FileChannel srcChannel = srcStream.getChannel();

        File dstFile = new File("d:\\transferCopy.txt");
        FileOutputStream dstStream = new FileOutputStream(dstFile);
        FileChannel dstChannel = dstStream.getChannel();

        dstChannel.transferFrom(srcChannel,0,srcChannel.size());

        srcChannel.close();
        dstChannel.close();
        srcStream.close();
        dstStream.close();
    }
}
